package com.llgz.hotelmanageapi.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.llgz.hotelmanageapi.common.CommonResult;
import com.llgz.hotelmanageapi.pojo.DAO.CheckinInfoDAO;
import com.llgz.hotelmanageapi.pojo.DO.*;
import com.llgz.hotelmanageapi.pojo.DO.RoomChangeInfo;
import com.llgz.hotelmanageapi.pojo.DO.RoomChangeInfo;
import com.llgz.hotelmanageapi.pojo.VO.CheckinInfoVO;
import com.llgz.hotelmanageapi.service.impl.RoomChangeInfoServiceImpl;
import com.llgz.hotelmanageapi.service.impl.RoomChangeInfoServiceImpl;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 换房登记信息表 前端控制器
 * </p>
 *
 * @author Bernie_fang
 * @since 2021-07-19
 */
@RestController
@RequestMapping("/roomChangeInfo")
@RequiresRoles(value = {"root", "admin", "manager", "reception"}, logical = Logical.OR)
public class RoomChangeInfoController {
    @Autowired
    RoomChangeInfoServiceImpl roomChangeInfoService;

    /**
     * @MethodName addRoomChangeInfo
     * @Params * @param RoomChangeInfo
     * @Description 添加
     * @Return CommonResult
     */
    @PostMapping("/addRoomChangeInfo")
    @ApiOperation(value = "添加", response = CommonResult.class, httpMethod = "POST")
    public CommonResult addRoomChangeInfo(@RequestBody RoomChangeInfo roomChangeInfo){
        boolean save = roomChangeInfoService.save(roomChangeInfo);
        return CommonResult.successResponse(save);
    }

    /**
     * @MethodName getRoomChangeInfoList
     * @Params * @param RoomChangeInfo
     * @Description 查找全部
     * @Return CommonResult
     */
    @GetMapping("/getRoomChangeInfoList")
    @ApiOperation(value = "查找", response = CommonResult.class, httpMethod = "GET")
    public CommonResult getRoomChangeInfoList(@RequestParam String query,@RequestParam Integer pageNum,@RequestParam Integer pageCount){
        QueryWrapper<RoomChangeInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("modified_time");
        if (query != null && !query.isEmpty()){
            queryWrapper.like("",query);
        }
        IPage<RoomChangeInfo> page = roomChangeInfoService.page(new Page<>(pageNum, pageCount), queryWrapper);
        return CommonResult.successResponse(page);
    }

    @GetMapping("/getRoomChangeInfoById")
    @ApiOperation(value = "查找(Id)", response = CommonResult.class, httpMethod = "GET")
    public CommonResult getRoomChangeInfoById(@RequestParam String id){
        RoomChangeInfo category = roomChangeInfoService.getOne(new QueryWrapper<RoomChangeInfo>().eq("id", id));
        return CommonResult.successResponse(category);
    }

    /**
     * @MethodName updateRoomChangeInfo
     * @Params * @param RoomChangeInfo
     * @Description 更新
     * @Return CommonResult
     */
    @PostMapping("/updateRoomChangeInfo")
    @ApiOperation(value = "更新", response = CommonResult.class, httpMethod = "POST")
    public CommonResult updateRoomChangeInfo (@RequestBody RoomChangeInfo roomChangeInfo){
        boolean b = roomChangeInfoService.updateById(roomChangeInfo);
        return CommonResult.successResponse(b);
    }

    /**
     * @MethodName deleteRoomChangeInfo
     * @Params * @param RoomChangeInfo
     * @Description 删除（多选）
     * @Return CommonResult
     */
    @PostMapping("/deleteRoomChangeInfo")
    @ApiOperation(value = "删除（多选）", response = CommonResult.class, httpMethod = "POST")
    public CommonResult deleteRoomChangeInfo (@RequestBody List<String> ids){
        boolean b = roomChangeInfoService.removeByIds(ids);
        return CommonResult.successResponse(b);
    }

    @PostMapping("/getExChangRoomInfo")
    @ApiOperation(value = "获取编辑框信息",response = CommonResult.class,httpMethod = "POST")
    public CommonResult getExChangRoomInfo(@RequestParam String id){
        CheckinInfoVO exChangRoomInfo = roomChangeInfoService.getExChangRoomInfo(id);
        return CommonResult.successResponse(exChangRoomInfo);
    }

    @PostMapping("/ChangeRoomInfo")
    @ApiOperation(value = "修改入住信息")
    public CommonResult ChangeRoomInfo(@RequestBody CheckinInfoVO checkinInfoVO){
        roomChangeInfoService.ChangeRoomInfo(checkinInfoVO);
        return CommonResult.successResponse(null);
    }

    @PostMapping("/checkInWithRoomChange")
    @ApiOperation(value = "登记入住")
    public CommonResult checkInWithRoomChange(@RequestBody CheckinInfoDAO checkinInfoDAO){
        roomChangeInfoService.checkInWithRoomChange(checkinInfoDAO);
        return CommonResult.successResponse(null);
    }

}

